package coc

import (
	"fmt"
	"strings"
	"trpg-message/commands/trpg"
	"trpg-message/entity"
)

type En struct {
}

func (en En) Handle(message entity.Message, argStr string) string {
	splitArg := strings.Split(argStr, " ")
	var attr int32
	if len(splitArg) != 2 {
		return "错误的参数，请参考help"
	}
	attributes := roomDao.GetRoomBindCharacter(message.RoomId, message.Creator)
	if attributes == nil {
		return "未设置角色属性值，请设置"
	}
	attrSet, ok1 := attributes[splitArg[0]]
	if ok1 == false {
		return "未设置角色属性值，请设置"
	}
	attr = attrSet
	add := splitArg[1]
	checkResult, rand := trpg.GetCheckResult(attr, message.RoomId)
	result := fmt.Sprintf("「%v」进行「%v」属性的成长检定：1d100=%v/%v", splitArg[0], splitArg[1], rand, attr)
	switch checkResult {
	case 0, 1, 2, 3:
		result += "成长鉴定失败！无成长"
		break
	case 4, 5:
		addNum, addNumInt := trpg.GetLongRand(add, 1)
		attributes[splitArg[0]] = attrSet + int32(addNumInt)
		roomDao.SetCharacterAttr(message.RoomId, message.Creator, attributes)
		result += fmt.Sprintf("成长检定成功！「%v」的「%v」属性增加%v", splitArg[0], splitArg[1], addNum)
		break
	}
	return result
}
